#include "TimeFormatter.h"

TTimeFormatter::TTimeFormatter(const TDesC& aTimeFormat, TMode aMode)
  : iTimeFormatSpec(aTimeFormat),
    iMode(aMode)
{}

TPtrC TTimeFormatter::FormatTimeL(const TTime& aTime)
{
  iFormatBuffer.Zero();

  aTime.FormatL(iFormatBuffer, iTimeFormatSpec);

  if ( iMode == EPrependWith0BasedNumberOfDays )
  {
    const TTime zeroTime(0);
    TTimeIntervalDays days = aTime.DaysFrom(zeroTime);

    if ( days.Int() > 0 )
    {
      TBuf<10> daysBuf;
      _LIT(KDaysFormat, "%d  ");
      daysBuf.Format(KDaysFormat(), days.Int());

      iFormatBuffer.Insert(0, daysBuf);
    }
  }

  return iFormatBuffer;
}
